import request from '../utils/http-utils.js'

// 帖子相关 api
// TODO 管理员添加帖子
const blogApi = {
	ByPage: '/content/back/blog/page',
	BlogDetail: '/content/back/blog/detail',
	TopBlog: '/content//back/blog/top'
}

// 关于相关
const aboutApi = {
	AboutOperate: '/content/back/about',
	ByPage: '/content/back/about/page'
}

// =======================================================
/**
 * 分页获取 blog 列表
 * @param {Object} page
 */
export function getBlogByPage (page) {
	return request({
		url: blogApi.ByPage,
		method: 'post',
		data: page
	})
}

/**
 * 查阅帖子详情
 * @param {Object} id
 */
export function getBlogDetail(id) {
	return request({
		url: blogApi.BlogDetail + `/${id}`,
		method: 'get'
	})
}

/**
 * 置顶帖子
 */
export function enableBlogTop(state, id) {
	return request({
		url: blogApi.TopBlog + `/${state}/${id}`,
		method: 'put'
	})
}
// =======================================================

/**
 * 添加相关
 * @param {Object} data
 */
export function addAbout(data) {
	return request({
		url: aboutApi.AboutOperate,
		method: 'post',
		data: data
	})
}

/**
 * 修改
 * @param {Object} data
 */
export function updateAbout(data) {
	return request({
		url: aboutApi.AboutOperate,
		method: 'put',
		data: data
	})
}

/**
 * 根据 ID 获取 about
 * @param {Object} data
 */
export function getAboutById(id) {
	return request({
		url: aboutApi.AboutOperate + `/${id}`,
		method: 'get'
	})
}

/**
 * 删除about 
 * @param {Object} id
 */
export function deleteAboutById(id) {
	return request({
		url: aboutApi.AboutOperate + `/${id}`,
		method: 'delete'
	})
}

/**
 * 分页获取
 * @param {Object} page
 */
export function getAboutByPage (page) {
	return request({
		url: aboutApi.ByPage,
		method: 'post',
		data: page
	})
}

/**
 * 启用 关闭 about
 * @param {Object} id
 * @param {Object} enable
 */
export function enableAbout(id, enable) {
	return request({
		url: aboutApi.AboutOperate + `/${id}/${enable}`,
		method: 'put'
	})
}

